#include "World.h"

#include "Remote.h"

World* World::_instance = 0;
float THRESHOLD = .9;

World::World() {}


World::~World() {
}

void World::init(){
	BZRC* com = Remote::instance();

	_constants.clear();
	_flags.clear();
	_tanks.clear();
	_obstacles.clear();
	_other_tanks.clear();
	_shots.clear();
	_teams.clear();

	std::vector<Command> init;
	init.push_back(Command(-1, -1, -1, false, false, CONSTANTS | OBSTACLES | TEAMS | MY_TANKS | OTHER_TANKS | FLAGS | SHOTS));
	com->do_commands(init);

	_occgrids.resize(_tanks.size());

	for(unsigned int i = 0; i < _constants.size(); i ++){
		if(_constants[i].name.compare("worldsize") == 0){
			size = std::atoi(_constants[i].value.c_str());
		}
		if(_constants[i].name.compare("truepositive") == 0){
			truePositive = std::atof(_constants[i].value.c_str());
		}
		if(_constants[i].name.compare("truenegative") == 0){
			trueNegative = std::atof(_constants[i].value.c_str());
		}
	}
}

World* World::instance() {
	if (!_instance)
		_instance = new World();

	return _instance;
}

Command World::update() {
	BZRC* com = Remote::instance();

	return Command(-1, -1, -1, false, false, MY_TANKS | OTHER_TANKS | FLAGS | SHOTS);
}

vector <constant_t> & World::constants() {
	return _constants;
}

vector <flag_t> & World::flags() {
	return _flags;
}

vector <tank_t> & World::tanks() {
	return _tanks;
}

vector <obstacle_t> & World::obstacles() {
	return _obstacles;
}

vector <otank_t> & World::other_tanks() {
	return _other_tanks;
}

vector <shot_t> & World::shots() {
	return _shots;
}

vector <team_t> & World::teams() {
	return _teams;
}
vector <occgrid_t> & World::occgrids(){
	return _occgrids;
}

int World::getSize(){
	return size;
}

float World::getTruePositive(){
	return truePositive;
}

float World::getTrueNegative(){
	return trueNegative;
}

vector <constant_t> * World::constantsP() {
	return &_constants;
}

vector <flag_t> * World::flagsP() {
	return &_flags;
}

vector <tank_t> * World::tanksP() {
	return &_tanks;
}

vector <obstacle_t> * World::obstaclesP() {
	return &_obstacles;
}

vector <otank_t> * World::other_tanksP() {
	return &_other_tanks;
}

vector <shot_t> * World::shotsP() {
	return &_shots;
}

vector <team_t> * World::teamsP() {
	return &_teams;
}

vector <occgrid_t> * World::occgridsP(){
	return &_occgrids;
}